package server;

import java.awt.Color;
import java.awt.Dimension;
import java.util.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import both.*;

public class ScoreboardTab extends JPanel {

	private JTable scoreboard;
	private Game game;
        

	public ScoreboardTab(GameShowServer server) {
		super();
		this.game = server.getGame();
		//setLocation(0, 0);               
                updateScoreboard();
                setName("scoreboard-tab");
		setVisible(true);
	}

	public void updateScoreboard() {
		String[] Headers = { StringFormatter.formatString("Team Name", StringFormatter.TITLE_STR), StringFormatter.formatString("Score", StringFormatter.TITLE_STR) };
                ArrayList<Team> teams = game.getRoster().teamsByScore();
		String[][] Names = new String[teams.size()][2];
		for (int i = 0; i < teams.size(); i++) {
			String name = teams.get(i).getName();
                        name = name.toLowerCase();
                        name = name.substring(0,1).toUpperCase()+name.substring(1);
			String score = String.valueOf(teams.get(i).getTeamScore());
			Names[i][0] = name;
			Names[i][1] = score;
		}
                System.out.println(teams);
		DefaultTableModel change = new DefaultTableModel(Names, Headers);
		scoreboard = new JTable(change);
                removeAll();
		add(new JScrollPane(scoreboard));
                scoreboard.setVisible(true);
	}

	public JTable getScoreboard() {
		return scoreboard;
	}

	public void setScoreboard(JTable gameScoreboard) {
		scoreboard = gameScoreboard;
	}

	public Game getGame() {
		return game;
	}

	public void setGame(Game game) {
		this.game = game;
	}
}
